<?php

namespace app\controller;

use think\Request;
use think\Log;

class BaseController extends Controller
{
    protected $uid;

    protected $user;

    protected $version;

    protected $agent;

    protected $size;

    protected $page;

    protected $offset;

    public function __construct(Request $request)
    {

        $param = $request->param();

        //Log::debug('url:'. $request->url(),['params' => $param]);

        //获取Jwt中用户id
        $this->uid = 1;

        $this->user = [];

        //版本号
        $this->version = '';

        //客户端标识 ios android h5 小程序
        $this->agent = '';

        //初始化请求页 请求条数 构建分页参数
        $this->page = isset($request['page']) &&  $request['page'] ? $request['page'] : '1';

        $this->size = isset($param['pageSize']) &&  $param['pageSize'] ? $param['pageSize'] : '10';

        $this->offset = ($this->page - 1) * $this->size;


    }

    protected function renderJson($data=[], $maxAge = 0)
    {

        $ret = ['code' => 200, 'message' => '', 'data' => $data];

        $response = json($ret);

        return $response;
    }
}